//
//  MainFirst_Magazine_TBV_WX.m
//  ZITHER
//
//  Created by weixin on 2018/10/18.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainFirst_Magazine_TBV_WX.h"

#import "MainFirst_Magazine_TBV_HeadCell_WX.h"
#import "MainFirst_Magazine_TBV_TitleCell_WX.h"
#import "MainFirst_Magazine_TBV_GoodsCell_WX.h"
#import "MainFirst_Magazine_TBV_FriedViewCel_WX.h"
#import "UgcDetailCummentHeadCell.h"
#import "UgcDetailCummentCell.h"

#import "MainFirst_Magazine_VC_WX.h"
#import "MainFirst_MagazineVideo_VC_WX.h"
#import "STViewController.h"

#import "ReportView.h"



@interface MainFirst_Magazine_TBV_WX()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)MainFirst_Magazine_VC_WX * vc;

@property (nonatomic,strong)BaseView * viewBg;

/** 有关tbv上下啦或者显示导航烂 */
/** 记录触发位置 */
@property (nonatomic,assign)CGFloat typeY;
/** 记录触发状态 0为不动 1为向下滑动 2为向上滑动 */
@property (nonatomic,assign)NSInteger stateIndex;

@end

@implementation MainFirst_Magazine_TBV_WX



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
//        BaseImageV *imageV = [BaseImageV initCustom:CGRectMake(0, 0, 100, 200) contentMode:2];
//        //    [imageV sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"]];
//        [self addSubview:imageV];
//
//        [imageV addBigImage];
    }
    return self;
}

-(void)setPgcId:(NSString *)pgcId{
    _pgcId = pgcId;
    [self loadData];
}


- (void)Starefreshing{
    
    if (self.page == 0 ) {
        [self loadData];
    }
    [self loadDataComment];
    
}

-(void)loadData{
    
    [[serviceDefualt loaduserPgcDetail:self.pgcId reponseObjctClass:[HomePageDetailModelData class]]subscribeNext:^(ResponseData * x) {

        if (x.success) {
            
            self.model = x.responseData;
            
            NSString *string =@"json\":";
            NSString *str = self.model.userPgc.pgcContent;
            
            if (str.length ==0) {
                return ;
            }
            
            NSArray *array = [str componentsSeparatedByString:string];
            
            if (array.count!=0 && array != nil && array.count!=1) {
                
            str = array[1];
            
            NSString *str1 = [str substringToIndex:str.length-1];
            
            NSData *objectData = [str1 dataUsingEncoding:NSUTF8StringEncoding];
            
            NSArray *jsonArrM = [NSJSONSerialization JSONObjectWithData:objectData
                                                                options:NSJSONReadingMutableLeaves
                                                                  error:nil];
                
                NSMutableArray *arrM = [[NSMutableArray alloc]init];
                
                for (NSDictionary *dic in jsonArrM) {
                    
                    HomePageDetailModelpgcJson *model = [HomePageDetailModelpgcJson yy_modelWithDictionary:dic];
                    
                    [arrM addObject:model];
                    
                }
                
                self.model.json = arrM;
                
            }

            [self loadDataComment];

        }else{
            if (![x.errorInfo isEqualToString:@"未登录"]) {
//                [Tools showTips:x.errorInfo];
            }
        }
        
        [self endRefreshing];
        [self reloadData];
    }];
}

-(void)loadDataComment{
    @weakify(self);
    [[serviceDefualt loadGetuserCommentList:self.pgcId relType:@"2" page:self.page reponseObjctClass:[UgcCommentListModel class]]subscribeNext:^(ResponseData * x) {
        @strongify(self);
        if (x.success) {
            self.total = x.responseRawData[@"data"][@"total"];
            /** 1.当用户第一次进来 */
            
            UgcCommentListModel* listModel = x.responseData;
            if (listModel.list.count == 0) {
                [self.mj_footer endRefreshing];
                if (!self.type) {
                    self.type = YES;
                    [self.mj_footer endRefreshingWithNoMoreData];
                    return ;
                }else{
                    if (listModel.list.count == 0) {
                        if (self.page == 0) {
                            [Tools showTips:@"暂无更多数据"];
                            [self.mj_header endRefreshing];
                            [self.mj_footer endRefreshing];
                        }else{
                            [self.mj_footer endRefreshingWithNoMoreData];
                        }
                        return ;
                    }
                }
                if (self.page == 0) {
                    self.arrMComment = [[NSMutableArray alloc]init];
                    [Tools showTips:@"暂无评论"];
                    [self.mj_header endRefreshing];
                    [self reloadData];
                }else{
                    [Tools showTips:@"没有更多的评论"];
                    [self.mj_header endRefreshing];
                    [self reloadData];
                    return ;
                }
            }else{
                if (self.page == 0) {
                    self.arrMComment = [[NSMutableArray alloc]init];
                    for (UgcCommentListModelSub *model in listModel.list) {
                        [self.arrMComment addObject:model];
                        if (model.sonCommentList.count!=0) {
                            for (UgcCommentListModelSub *model1 in model.sonCommentList) {
                                [self.arrMComment addObject:model1];
                            }
                        }
                    }
                }else{
                    for (UgcCommentListModelSub *model in listModel.list) {
                        [self.arrMComment addObject:model];
                        if (model.sonCommentList.count!=0) {
                            for (UgcCommentListModelSub *model1 in model.sonCommentList) {
                                [self.arrMComment addObject:model1];
                            }
                        }
                    }
                }
            }
            [self.mj_header endRefreshing];
            [self.mj_footer endRefreshing];
            [self reloadData];
            self.type = YES;
        }else{
            [Tools showTips:x.errorInfo];
            [self.mj_header endRefreshing];
            [self.mj_footer endRefreshing];
        }
    }];
}


-(void)defaultConfiguration{
    self.delegate = self;
    self.dataSource = self;
    self.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, kStatusBarHeight)];
    //等待webview资源加载完毕
    self.scrollEnabled = NO;
    
}

#pragma mark -- tabdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1+1+1+self.model.goodsList.count+self.arrMComment.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  [self getCell1:indexPath];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row == 0) {
        
//        return [self getHeadCell:index];
        
    }else if (indexPath.row<=1){
        
        HomePageDetailModelpgcJson *model = self.model.json[indexPath.row-1];

        if([model.type isEqualToString:@"video"]){
            MainFirst_MagazineVideo_VC_WX *vc = [[MainFirst_MagazineVideo_VC_WX alloc]init];
            vc.modelJson = model;
            [self.getNav pushViewController:vc animated:YES];
        }
        
//        return  [self getHomePageDetailModelpgcCell:index];
        
        
    }else if(indexPath.row>=1+1 && indexPath.row<1+1+self.model.goodsList.count){
        
        HomePageDetailModelGoodsList *model = self.model.goodsList[indexPath.row - (1+1)];
        
        [self didSelec:model];
        

//        return [self getHomePageGoodsCell:index];
        
        
    }else if(indexPath.row>=1+1+self.model.goodsList.count && indexPath.row<1+1+self.model.goodsList.count+1){
        NSLog(@"");
    }else{
        
        [self setAlertAction:indexPath];
        
    }
    
}


-(void)didSelec:(HomePageDetailModelGoodsList*)model{
    if ([model.type isEqualToString:@"1"]) {
        //brandNameNative goodNameNative 品牌 _goodsId
        STViewController *vc = [[STViewController alloc]init];
        vc.type = STControllerTypeHiddenNavBar;
        vc.goodId = model.goodsId;
        [self.getNav pushViewController:vc animated:YES];
    }else if ([model.type isEqualToString:@"2"]){
        //系列 _seriesId

    }else if ([model.type isEqualToString:@"3"]){
        //型号 _brandId

    }
}

-(void)loadUserRepelList{
    [[AccountService loadUserRepelList:100 reponseObjctClass:nil]subscribeNext:^(id  _Nullable x) {
        
    }];
}

-(void)setAlertAction:(NSIndexPath*)indexPath{
    UgcCommentListModelSub *model = self.arrMComment[indexPath.row-(1+1+self.model.goodsList.count+1)];
    
    QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
    }];
    
    QMUIAlertAction *action4 = [QMUIAlertAction actionWithTitle:@"回复" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
        //        [self btnClick:1];
        [self sendComment:indexPath];
    }];
    
    NSString *name = @"";
    
    if ([kUSER_INFO_MANAGER.userId isEqualToString:model.userId]) {
        name = @"删除";
    }else{
        name = @"举报";
    }
 
    
    QMUIAlertAction *ac2 = [QMUIAlertAction actionWithTitle:name style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
        
        if ([kUSER_INFO_MANAGER.userId isEqualToString:model.userId]) {
            [self removeComment:model index:indexPath];
        }else{
            ReportView *rep = [[ReportView alloc]initWithFrame:CGRectMake(0,0, kScreenW, kScreenH)];
            
            if (model.commentParentId.length != 0) {
                rep.typeId = model.commentMasterId;
            }else{
                rep.typeId = model.commentParentId;
            }
            rep.state = ReportViewStateComent;
            [rep show];
        }
        
    }];
    
    QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet];
    
    [alertController addAction:action4];
    
    [alertController addAction:action1];
    if (![kUSER_INFO_MANAGER.userId isEqualToString:model.userId]) {
        QMUIAlertAction *action3 = [QMUIAlertAction actionWithTitle:@"屏蔽用户" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
            
            [[AccountService loadUserRepelAdd:model.userId reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
                if (x.success) {
                    [Tools showTips:@"已屏蔽"];
                }else{
                    [Tools showTips:x.errorInfo];
                }
            }];
        }];
        [alertController addAction:action3];
    }
    
    
    [alertController addAction:ac2];
    
    [alertController showWithAnimated:YES];

}


-(void)removeComment:(UgcCommentListModelSub*)model index:(NSIndexPath*)indexPath{
    
    [[serviceDefualt loadDelUserCommentCommentId:model.commentId reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
        if (x.success) {
            NSInteger index = indexPath.row-(1+1+self.model.goodsList.count+1);
            
            UgcCommentListModelSub *model = self.arrMComment [index];
            NSMutableArray *arrIndexPath = [[NSMutableArray alloc]init];
            
            if (model.sonCommentList.count!=0) {
                for (int i = 0; i< model.sonCommentList.count; i++) {
                    [self.arrMComment removeObjectAtIndex:index+1];
                    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row+1+i inSection:0];
                    [arrIndexPath addObject:indexPath1];
                }
            }
            
            [self.arrMComment removeObjectAtIndex:index];
            
            if (self.arrMComment.count == 0) {
                [self reloadData];
                self.model.userPgc.commentCount = @"0";
//                [self setModel:self.model];
            }else{
                if (arrIndexPath.count ==0 ) {
                    [self beginUpdates];
                    [self deleteRowsAtIndexPaths:@[indexPath]  withRowAnimation:UITableViewRowAnimationTop];
                    [self endUpdates];
                    
                    self.model.userPgc.commentCount = [NSString stringWithFormat:@"%ld",[self.model.userPgc.commentCount integerValue]-1];
                    [self setModel:self.model];
                }else{
                    [self beginUpdates];
                    [arrIndexPath addObject:indexPath];
                    [self deleteRowsAtIndexPaths:arrIndexPath  withRowAnimation:UITableViewRowAnimationFade];
                    [self endUpdates];
                    
                    self.model.userPgc.commentCount = [NSString stringWithFormat:@"%ld",[self.model.userPgc.commentCount integerValue]-arrIndexPath.count];
                    
                    NSInteger indexnum = 1+1+self.model.goodsList.count;
                    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:indexnum inSection:0];
                    [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
//                    [self setModel:self.model];
                }
                
            }
            
            
            
//            [self.arrMComment removeObjectAtIndex:index];
//
//            if (self.arrMComment.count == 0) {
//                self.model.userPgc.commentCount = @"0";
////                indexnum = 1+1+self.model.goodsList.count;
//                [self reloadData];
//            }else{
//                self.model.userPgc.commentCount = [NSString stringWithFormat:@"%ld",[self.model.userPgc.commentCount integerValue]-1];
//                [self beginUpdates];
//                [self deleteRowsAtIndexPaths:@[indexPath]  withRowAnimation:UITableViewRowAnimationFade];
//                [self endUpdates];
//                NSInteger indexnum = 1+1+self.model.goodsList.count;
//                NSIndexPath *indexPath=[NSIndexPath indexPathForRow:indexnum inSection:0];
//                [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
//            }
       
            
            [Tools showTips:@"删除成功"];
        }else{
            [Tools showTips:x.errorInfo];
        }
    }];
}


-(void)sendComment:(NSIndexPath *)indexPath{
    if (indexPath.row - (1+1+self.model.goodsList.count+1)>=0) {
        UgcCommentListModelSub *model = self.arrMComment[indexPath.row-(1+1+self.model.goodsList.count+1)];
        /** 点击回复评论 */
        if ([model.isMaster isEqualToString:@"0"]) {
            /** 自己回复自己 */
            if (self.keyboard) {
                self.keyboard(model.nickName,self.pgcId, model.userId, @"2", model.commentId, model.commentId,1,indexPath.row);
            }
        }else{
            if (self.keyboard) {
                self.keyboard(model.nickName,self.pgcId, model.userId, @"2", model.commentId, model.commentMasterId,2,indexPath.row);
            }
        }
    }
}




-(UITableViewCell*)getCell1:(NSIndexPath*)index{
    
    if (index.row == 0) {
        
        return [self getHeadCell:index];
        
    }else if (index.row<=1){
        
        return  [self getMainFirst_Magazine_TBV_WebCel_WX:index];
//        return  [self getHomePageDetailModelpgcCell:index];
        
        
    }else if(index.row>=1+1 && index.row<1+1+self.model.goodsList.count){
        
        
        return [self getHomePageGoodsCell:index];
        
        
    }else if(index.row>=1+1+self.model.goodsList.count && index.row<1+1+self.model.goodsList.count+1){
        
        return [self getMainFirst_Magazine_TBV_FriedViewCel_WX:index];
        
    }else{
        
        return [self getCummentCell:index];
        
    }
        
}


-(UITableViewCell *)getUgcDetailCummentHeadCell_TokenCell:(NSIndexPath *)indexPath{
    UgcCommentListModelSub *model = self.arrMComment[indexPath.row-(1+1+self.model.goodsList.count+1)];

    static NSString *sectionCell = @"UgcDetailCummentHeadCell_TokenCell";
    UgcDetailCummentHeadCell_TokenCell *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[UgcDetailCummentHeadCell_TokenCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.indexPath = indexPath;

    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.modelComment = model;
    cell.viewLine.hidden = indexPath.row==0?YES:NO;
    //    cell.backgroundColor = [UIColor colorWithHex:@"f5f5f5"];
    
    return cell;
}


-(UITableViewCell *)getUgcDetailCummentCell_TokenCell:(NSIndexPath *)indexPath{
    UgcCommentListModelSub *model = self.arrMComment[indexPath.row-(1+1+self.model.goodsList.count+1)];
    static NSString *sectionCell = @"UgcDetailCummentCell_TokenCell";
    UgcDetailCummentCell_TokenCell *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[UgcDetailCummentCell_TokenCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    //    cell.backgroundColor = [UIColor colorWithHex:@"f5f5f5"];
    
    cell.modelComment = model;
    return cell;
}



-(UITableViewCell*)getHeadCell:(NSIndexPath*)index{
    static NSString *sectionCell = @"MainFirst_Magazine_TBV_HeadCell_WX";
    MainFirst_Magazine_TBV_HeadCell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[MainFirst_Magazine_TBV_HeadCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.model = self.model;
    cell.indexPath = index;
    return cell;
}


-(UITableViewCell*)getHomePageGoodsCell:(NSIndexPath*)index{
    
    HomePageDetailModelGoodsList *model = self.model.goodsList[index.row - (1+1)];
    static NSString *sectionCell = @"MainFirst_Magazine_TBV_GoodsCell_WX";
    MainFirst_Magazine_TBV_GoodsCell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[MainFirst_Magazine_TBV_GoodsCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.model = model;
    
    
    if (index.row - (1+1) == self.model.goodsList.count-1) {
        cell.index = 2;
    }else if (index.row - (1+1) == 0 ){
        cell.index = 0;
    }else{
        cell.index = 1;
    }
    
    return cell;
}

-(UITableViewCell*)getMainFirst_Magazine_TBV_WebCel_WX:(NSIndexPath*)index{
    
    static NSString *sectionCell = @"MainFirst_Magazine_TBV_WebCel_WX";
    MainFirst_Magazine_TBV_WebCel_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[MainFirst_Magazine_TBV_WebCel_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.pgcId = self.pgcId;
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.dataStr = self.model.userPgc.pgcContent;
    cell.backgroundColor = [UIColor randomColor];
    [cell setBlock:^(NSString * _Nonnull str) {
        
        if (self.block) {
            self.block(str);
        }
  

//        [imageV addBigImage];
        
//        BaseImageV *imageV = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
//        [imageV sd_setImageWithURL:[NSURL URLWithString:cell.PicSelectUrl] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"]];
//
//        [self.vc.view addSubview:imageV];
////        self.PicSelectUrl = url;
//        imageV.tag = 100;
//        [imageV showBigImage:100];
//        [self showBigImage:imageV];
//
//        BaseImageV *imageV = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 100, 200) contentMode:2];
//        //    [imageV sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"ucg_img_loding"]];
//        [self addSubview:imageV];
     
    }];
    return cell;
}

-(UITableViewCell*)getHomePageDetailModelpgcCell:(NSIndexPath*)index{
    static NSString *sectionCell = @"MainFirst_Magazine_TBV_TitleCell_WX";
    MainFirst_Magazine_TBV_TitleCell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
    cell = [[MainFirst_Magazine_TBV_TitleCell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    return cell;

}

-(UITableViewCell*)getMainFirst_Magazine_TBV_FriedViewCel_WX:(NSIndexPath*)index{
    HomePageDetailModelData *model = self.model;
    static NSString *sectionCell = @"MainFirst_Magazine_TBV_FriedViewCel_WX";
    MainFirst_Magazine_TBV_FriedViewCel_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[MainFirst_Magazine_TBV_FriedViewCel_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.model = model;
    cell.total= self.total;
    cell.indexPath = index;
    
    [cell setLikeSuccess:^{
        
//        [self reloadRowsAtIndexPaths:index withRowAnimation:UITableViewRowAnimationAutomatic];
    }];
    
    return cell;
}


-(UITableViewCell*)getCummentCell:(NSIndexPath*)index{
    
     UgcCommentListModelSub *model = self.arrMComment[index.row-(1+1+self.model.goodsList.count+1)];
    if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
        if ([model.isMaster isEqualToString:@"0"]) {
            return [self getUgcDetailCummentHeadCell_TokenCell:index];
        }else{
            return [self getUgcDetailCummentCell_TokenCell:index];
            //            return [self getUgcDetailCummentCell:indexPath];
            
        }
    }else{
        
        NSLog(@"%@",model.isMaster);
        if ([model.isMaster isEqualToString:@"0"]) {
            static NSString *sectionCell = @"UgcDetailCummentHeadCell";
            UgcDetailCummentHeadCell *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
            if (cell == nil) {
                cell = [[UgcDetailCummentHeadCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
            }
            cell.selectionStyle = UITableViewCellSeparatorStyleNone;
            cell.index = 1;
            cell.modelComment = model;
            
            return cell;
            
        }else{
            static NSString *sectionCell = @"UgcDetailCummentCell";
            UgcDetailCummentCell *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
            if (cell == nil) {
                cell = [[UgcDetailCummentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
            }
            cell.selectionStyle = UITableViewCellSeparatorStyleNone;
            cell.index = 1;
            cell.modelComment = model;
            return cell;
        }
    }
    

}

- (MainFirst_Magazine_VC_WX *)vc{
    if (!_vc) {
        _vc = (MainFirst_Magazine_VC_WX*)[self getViewController:[MainFirst_Magazine_VC_WX class]];
    }
    return _vc;
}

-(void)showBigImage:(UIImageView*)imageView{
    self.imageV = imageView;
    UIImageView *imageV = imageView;
    // self.model.fileList[selectIndex-100];
    
    if (!self.imagePreviewViewController) {
        self.imagePreviewViewController = [[QMUIImagePreviewViewController alloc] init];
        self.imagePreviewViewController.imagePreviewView.delegate = self;
        
        // QMUIImagePreviewViewController 对于以 window 的方式展示的情况，默认会开启手势拖拽退出预览功能。
        // 如果使用了手势拖拽，并且退出预览时需要飞到某个 rect，则需要实现这个 block，在里面自己去 exit，如果不实现这个 block，退出动画会使用 fadeOut 那种
        
    }
    @weakify(self);
    self.imagePreviewViewController.customGestureExitBlock = ^(QMUIImagePreviewViewController *aImagePreviewViewController, QMUIZoomImageView *currentZoomImageView) {
        @strongify(self);
        UIImageView *imageV1 = imageView;
        CGRect rect = [imageV1 convertRect:imageV1.frame toView:nil];
        /** 微调 */
        rect.origin.x -= 10;
        rect.origin.y -= 10;
        [aImagePreviewViewController exitPreviewToRectInScreenCoordinate:rect];
        
    };
    self.imagePreviewViewController.imagePreviewView.currentImageIndex = 0;// 默认查看的图片的 index
    
    [self.imagePreviewViewController startPreviewFromRectInScreenCoordinate:[imageV convertRect:imageV.frame toView:nil] cornerRadius:imageV.layer.cornerRadius];
}


#pragma mark - <QMUIImagePreviewViewDelegate>

- (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView {
    return 1;
}

- (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index {
    // 模拟异步加载的情况
    zoomImageView.reusedIdentifier = @(index);
    [zoomImageView showLoading];
    
    UIImageView *imageV = self.imageV;
    [zoomImageView hideEmptyView];
    zoomImageView.image = imageV.image;
    
    
}

- (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index {
    return QMUIImagePreviewMediaTypeImage;
}

#pragma mark - <QMUIZoomImageViewDelegate>

- (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location {
    //点击缩回
    self.imagePreviewViewController.customGestureExitBlock(self.imagePreviewViewController, zoomImageView);
}


-(BaseView *)viewBg{
    if (!_viewBg) {
        _viewBg = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kStatusBarHeight2)];
        _viewBg.backgroundColor = [UIColor whiteColor];
//        _viewBg.hidden = YES;
        [self.superview addSubview:_viewBg];
        _viewBg.hidden = YES;

    }
    return _viewBg;
}


-(MainFirst_Magazine_TBV_WebCel_WX *)webCell{
    NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
    MainFirst_Magazine_TBV_WebCel_WX * cell = (MainFirst_Magazine_TBV_WebCel_WX *)[self cellForRowAtIndexPath:index]; //即为要得到的cell
    return cell;
    
}

//实现scrollView代理
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    //全局变量记录滑动前的contentOffset
    self.typeY = scrollView.contentOffset.y - (kStatusBarHeight+5);//判断上下滑动时
}

/**
 y : kStatusBarHeight+5  ~ -(50+kStatusBarHeight+5)
 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.y<20) {
        self.vc.leb.hidden = NO;
        self.vc.btn.hidden = NO;
        self.vc.btnMore.hidden = NO;
    }else{
        
        if (self.typeY >= scrollView.contentOffset.y) {
            //            NSLog(@"开始下滑");
            self.vc.leb.hidden = NO;
            self.vc.btn.hidden = NO;
            self.vc.btnMore.hidden = NO;
        }else{
            //            NSLog(@"开始上滑动");
            self.vc.leb.hidden = YES;
            self.vc.btn.hidden = YES;
            self.vc.btnMore.hidden = YES;
        }
    }
    //    NSLog(@"scrollView.contentOffset.y = %f",scrollView.contentOffset.y);
    if (scrollView.contentOffset.y<kScreenW/375.0*413) {
        self.viewBg.hidden = YES;
    }else{
        self.viewBg.hidden = NO;
    }
    //    NaviHeight
    
    CGFloat y = Is_Iphone_X_Series?44:22;
    if (scrollView.contentOffset.y == y) {
        self.vc.btn.hidden = NO;
        self.vc.btnMore.hidden = NO;
    }
    
}
@end
